package cn.itcast.hotel.config;

import cn.itcast.hotel.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @作者 itcast
 * @创建日期 2021/11/6 14:40
 **/
@Configuration
public class MqConfig {

    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.HOTEL_EXCHANGE);
    }

    @Bean
    Queue queueInsert(){
        return new Queue(MqConstants.HOTEL_INSERT_QUEUE);
    }

    @Bean
    Queue queueDelete(){
        return new Queue(MqConstants.HOTEL_DELETE_QUEUE);
    }

    @Bean
    Binding insertBinding(){
        return BindingBuilder.bind(queueInsert()) // 队列
                .to(topicExchange())  // 交换机
                .with(MqConstants.HOTEL_INSERT_KEY); // route_key
    }

    @Bean
    Binding deleteBinding(){
        return BindingBuilder.bind(queueDelete()) // 队列
                .to(topicExchange())  // 交换机
                .with(MqConstants.HOTEL_DELETE_KEY); // route_key
    }
}
